package com.example.service;


import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.ObjectUtil;
import com.example.entity.City;
import com.example.mapper.CityMapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * 城市组织信息业务层
 */
@Service
public class CityService {
    @Resource
    private CityMapper cityMapper;

    public void add(City city) {
        //进行逻辑处理
            cityMapper.insert(city);
        }

    public PageInfo<City> selectPage(City city, Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        List<City> list;
        if(ObjectUtil.isNotEmpty(city.getName())){
            list = cityMapper.selectByName(city.getName());
        } else {
            list = cityMapper.selectAll();
        }

        return PageInfo.of(list);



    }

    public void updateById(City city) {
        cityMapper.updateById(city);
    }

    public void deleteById(Integer id) {
        cityMapper.deleteById(id);
    }

    public List<City> selectAll() {
        return cityMapper.selectAll();
    }
}

